extends State
class_name Playerwallslide
@onready var player_sprite: AnimatedSprite2D = $"../../PlayerSprite"
var wall_gravity:float = Autoload.gravity * 0.3
var wall_flag:bool = true
@export var Velocity:float = 400.0

func enter():
	print("进入滑墙状态")
	wall_flag = true
	character.velocity.y *= 0.1
	Autoload.lock_time = 0.1
	Autoload.wolf_time = Autoload.wolf_time_stander

func update(delta):
	if Input.is_action_just_released("玩家向左走") or Input.is_action_just_released("玩家向右走"):
		wall_flag = false
		Autoload.wolf_time = -100
		transition_requested.emit("Playerjump")
	if Input.is_action_just_pressed("玩家跳跃") and Autoload.lock_time < 0 :
		if character.is_on_wall() or Autoload.wolf_time > 0:
			wall_flag = false
			transition_requested.emit("Playerwalljump")
	#if Input.is_action_pressed("冲刺") and Autoload.dashflag == true and Autoload.lock_time < 0 :
		#wall_flag = false
		#Autoload.boolswap(player_sprite.flip_h)
		#transition_requested.emit("Playerdash")
	
func physics_update(delta):
	Autoload.wolf_time -= delta
	Autoload.lock_time -= delta
	character.velocity.y += wall_gravity * delta
	var direction = Input.get_axis("玩家向左走","玩家向右走")
	if (direction > 0):
		player_sprite.flip_h = 0
	if (direction < 0):
		player_sprite.flip_h = 1
	if direction:
		character.velocity.x = direction * Velocity
	character.move_and_slide()
